/**
 * 2017，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SalesRptServiceImpl.java
 * Created：		2017年4月27日
 * Creator：		wolv
 */
package com.thor.palmmall.impl.rpt.sales;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.thor.commons.exception.ThorServiceException;
import com.thor.commons.util.Assert;
import com.thor.palmmall.api.rpt.Report;
import com.thor.palmmall.api.rpt.sales.DailySalesReportParam;
import com.thor.palmmall.api.rpt.sales.MonthSalesReport;
import com.thor.palmmall.api.rpt.sales.SalesRptService;
import com.thor.palmmall.dao.rpt.sales.PMonthSalesReport;
import com.thor.palmmall.dao.rpt.sales.SalesRptDao;

/**
 * @author wolv
 *
 */
public class SalesRptServiceImpl implements SalesRptService {

  @Override
  public Report getReport(DailySalesReportParam param) throws ThorServiceException {
    Assert.assertArgumentNotNull(param, "param");

    return salesRptDao.calcDailyReport(param);
  }

  @Autowired
  private SalesRptDao salesRptDao;

  @Override
  public Report getDailySalesReport(DailySalesReportParam param) throws ThorServiceException {

    Assert.assertArgumentNotNull(param, "param");

    return salesRptDao.calcDailySalesReport(param);
  }

  @Override
  public Report getMonthSalesReport(DailySalesReportParam param) throws ThorServiceException {
    Assert.assertArgumentNotNull(param, "param");

    return salesRptDao.calcMonthSalesReport(param);
  }

  @Override
  public List<MonthSalesReport> queryMonthReport(DailySalesReportParam param)
      throws ThorServiceException {
    List<PMonthSalesReport> pReports = salesRptDao.queryMonthReport(param);
    List<MonthSalesReport> reports = new ArrayList<MonthSalesReport>();
    for (PMonthSalesReport pRpt : pReports) {
      MonthSalesReport rpt = new MonthSalesReport();
      rpt.setAmount(pRpt.getAmount());
      rpt.setDate(pRpt.getDate());
      rpt.setStoreId(pRpt.getStoreId());
      reports.add(rpt);
    }
    return reports;
  }

  @Override
  public List<MonthSalesReport> queryFloorSalesByMonth(DailySalesReportParam param)
      throws ThorServiceException {
    List<PMonthSalesReport> pReports = salesRptDao.querySalesReportByMonth(param);
    List<MonthSalesReport> reports = new ArrayList<MonthSalesReport>();
    for (PMonthSalesReport pRpt : pReports) {
      MonthSalesReport rpt = new MonthSalesReport();
      rpt.setAmount(pRpt.getAmount());
      rpt.setDate(pRpt.getDate());
      rpt.setFloor(pRpt.getFloor());
      rpt.setStoreId(pRpt.getStoreId());
      reports.add(rpt);
    }
    return reports;
  }

  @Override
  public Report getFloorMonthSalesReports(DailySalesReportParam param) throws ThorServiceException {
    Assert.assertArgumentNotNull(param, "param");
    return salesRptDao.calcFloorMonthSalesReport(param);
  }

}
